package cn.enjoy.service.impl;

import cn.enjoy.annotation.Log;
import cn.enjoy.annotation.LogSpel;
import cn.enjoy.entity.User;
import cn.enjoy.mapper.UserMapper;
import cn.enjoy.service.IUserService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author K
 */
@Service
@AllArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    private final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    private UserMapper userMapper;

    @Override
    public void addUser() {
        logger.info("执行了添加用户的操作");
    }

    @Override
    @Log(operationName = "查询所有用户", operationType = "select")
    public List<User> findAll() {
        return baseMapper.selectList(new QueryWrapper<>());
//        return userMapper.findAll();
    }

    @Override
    @LogSpel(type = "insert", description = "新增用户", spel = "'用户名：'+#user.name")
//    @LogSpel(type = "insert", description = "新增用户", spel = "'用户名：'+#root[0].name")
    public void logSpel(User user) {
        logger.info(user.toString());
    }

    @Override
    @DS("slave_1")
    public User selectByIdSlave1(Long id) {
        return userMapper.selectById(id);
    }

}
